﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using AIO.Entity.Base;

namespace AIO.Entity
{
    /// <summary>
    /// 教师信息
    /// </summary>
    [Table("BH01")]
    public class Teacher : BaseEntity
    {
        /// <summary>
        /// 姓名
        /// </summary>
        [Required]
        [Column("BH001"), MaxLength(50)]
        public string? Name { get; set; }

        /// <summary>
        /// 姓氏
        /// </summary>
        [Required]
        [Column("BH002"), MaxLength(30)]
        public string? FirstName { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [Required]
        [Column("BH003"), MaxLength(30)]
        public string? LastName { get; set; }

        /// <summary>
        /// 身份证号
        /// </summary>
        [Required]
        [Column("BH005"), MaxLength(20)]
        public string? IDNo { get; set; }

        /// <summary>
        /// 银行卡号(后期需单独实现银行卡实体)
        /// </summary>
        [Column("BH006"), MaxLength(25)]
        public string? CardNo { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [Column("BH007"), MaxLength(150)]
        public string? Email { get; set; }

        /// <summary>
        /// 籍贯
        /// </summary>
        [Column("BH008")]
        public string? Origin { get; set; }

        /// <summary>
        /// 所在省份
        /// </summary>
        [Column("BH009"), MaxLength(50)]
        public string? Province { get; set; }

        /// <summary>
        /// 所在城市
        /// </summary>
        [Column("BH010"), MaxLength(50)]
        public string? City { get; set; }

        /// <summary>
        /// 所在区县街道门牌号
        /// </summary>
        [Column("BH011"), MaxLength(150)]
        public string? Region { get; set; }

        /// <summary>
        /// 生活地址
        /// </summary>
        [NotMapped]
        public string? Address
        {
            get
            {
                return this.Province + this.City + this.Region;
            }            
        }


        /// <summary>
        /// 邮编
        /// </summary>
        [Column("BH012"), MaxLength(15)]
        public string? PostalCode { get; set; }
        /// <summary>
        /// 手机号
        /// </summary>
        [Column("BH013"), MaxLength(50)]
        public string? PhoneNumber { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        [Column("BH014", TypeName = "tinyint")]
        public GenderEnum? Gender { get; set; }
        /// <summary>
        /// 所属系部
        /// </summary>
        [Column("BH015")]
        [ForeignKey("A01")]
        public Department? Department { get; set; }

        /// <summary>
        /// 教师单位顺序
        /// </summary>
        [Required]
        [Column("BH016")]
        public int TeacherOrder { get; set; }

        /// <summary>
        /// 教师工号(10位:U+男生M女生F+入职年份后2位+教师单位2位代码+4位顺序码 UM23230001)
        /// </summary>
        [NotMapped]
        public string? TeacherNo
        {
            get
            {
                string No = "T";
                No += Gender == GenderEnum.男 ? "M" : "F";
                No += CreateTime.Year % 100;
                No += this.Department == null ? "XX" : Department.Code;
                No += TeacherOrder.ToString().PadLeft(4, '0'); // 将数字前缀补0,直到4位为止.1=>0001
                return No;
            }
        }

    }
}
